package demo.chain.exception;


import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author : feixiang.li
 * @since : 2025-09-17 18:01
 */
public class ValidatorContext {


    private int currentIndex = 0;

    private boolean isStop = false;

    private Object obj;

    private final List<String> errorList = new ArrayList<>();


    public Integer getCurrentIndex() {
        return currentIndex;
    }

    public String getError() {
        if (this.errorList.isEmpty()) {
            return null;
        }
        return errorList.toString();
    }

    public ValidatorContext(Object value) {
        this.obj = value;
    }

    public void stop() {
        this.isStop = true;
    }

    public boolean isStop() {
        return this.isStop;
    }


    public void doNext(Object obj) {
        this.currentIndex++;
        this.obj = obj;
    }

    public void appendError(String error) {
        if (error == null) {
            return;
        }
        this.errorList.add(error);
    }
}

